<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.ld.com/shield/tags" prefix="shield"%>
<%@ page trimDirectiveWhitespaces="true" %>
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>${applicationScope.projectName }</title>
		<link rel="stylesheet" href="${ctxPath }/css/login.css?20190411114757">
		<%-- 有项目名的时候需要定义 --%>
		<link rel="shortcut icon" type="image/x-icon" href="${ctxPath }/favicon.ico?20190226105413">
	</head>
	
	<body>
		<%-- <div class="hearder"><h2>${applicationScope.projectName }</h2></div> --%>
		<div class="login-box clearfix">
			<div class="login-hed">${applicationScope.projectName }</div>
			<div class="login-content" style="width: 90%;">
				<h2>系统初始化</h2>
				<form action="${ctxPath }/systemInit" method="post" id="initForm">
					<shield:token/>
					<fieldset style="border-radius: 5px;padding: 5px;">
						<legend style="margin-left: 14px;font-size: 17px;font-weight: bold;">项目设置</legend>
						<ul>
							<li><label>项目名称</label><input type="text" name="projectName" id="projectName" placeholder="项目名称" value="${applicationScope.projectName }"><span></li>
						</ul>
					</fieldset>
					<fieldset style="border-radius: 5px;padding: 5px;margin-top:10px;">
						<legend style="margin-left: 14px;font-size: 17px;font-weight: bold;">用户设置</legend>
						<ul>
							<li><label>内置用户【system/admin/testkevin】的密码</label><input type="password" name="password" id="password" placeholder="登录密码"><span></li>
						</ul>
					</fieldset>
					<fieldset style="border-radius: 5px;padding: 5px;margin-top:10px;">
						<legend style="margin-left: 14px;font-size: 17px;font-weight: bold;">密码设置</legend>
						<ul>
							<li><label>druid数据库连接池用户名</label><input type="text" name="druidUserName" placeholder="druid数据库连接池用户名"><span></li>
							<li><label>druid数据库连接池密码</label><input type="password" name="druidPassword" placeholder="druid数据库连接池密码"><span></li>
							<li><label>swagger访问用户名</label><input type="text" name="swaggerUserName" placeholder="swagger访问用户名"><span></li>
							<li><label>swagger访问密码</label><input type="password" name="swaggerPassword" placeholder="swagger访问密码"><span></li>
						</ul>
					</fieldset>
					<div class="form-button">
						<p><input type="submit" id="submitbtn" class="a-button" value="提交" style="width: 60px;"/></p>
					</div>
				</form>
				<span class="tips" style="color: #e01222;">建议您修改com.ld.common.config.ProjectSecurityKey类中的密钥，避免因使用开源项目造成的密钥泄露。</span>	
			</div>
			
		</div>
		<div class="footer">版权所有 © 2020 Software Center - 绿盾技术部项目组. v${applicationScope.version }</div>
		<script type="text/javascript" src="${ctxPath }/js/lib/jquery-1.12.4.min.js?20190117152252"></script>
		<script type="text/javascript">
		var initForm = $('#initForm');
		var url = initForm.attr('action');
		initForm.submit(function() {
			login();
			return false;
		});
		var check = function() {
			var result = true;
			initForm.find(":input:not(:submit)").each(function(){
				var inputE = $(this);
				if (inputE.val() == '') {
					inputE.focus();
					alert(inputE.prev().text()+"不能为空！");
					result = false;
					return false;
				}
			});
			return result;
		}
		var login = function(){
			if (check()) {
				setTimeout(function() {
					var submitBtnE = $("#submitbtn");
					submitBtnE.data("v", submitBtnE.val()).val('处理中...').prop("disabled", true);
					
					$.post(url, initForm.serialize(), function(data) {
						submitBtnE.val(submitBtnE.data("v")).prop("disabled", false);
						if(data.message){
							alert(data.message)
						}
						if (data.success) {
							window.location.reload();
						}
					});
				}, 0);
			}
		}

		//替换回车提交
		var $inp = initForm.find(':input:not(:radio,:checkbox)');
		$inp.bind('keypress', function (e) {
		    var key = e.which;
		    if ( key == 13 || (e.ctrlKey && key == 13 ) ) {
		        e.preventDefault();
		        if (this.type == "submit") {
		        	this.click();
		        	return;
		        }
		        var nxtIdx = $inp.index(this) + 1;
		        var nxtIpt = $inp.eq(nxtIdx);
		        if (nxtIpt.length>0) {
		        	nxtIpt.focus();
		        	if (nxtIpt.is(":submit")) {
		        		nxtIpt.click();
			        }
		        } else {
		        	$("#submitbtn").click();
		        }
		    }
		});
		</script>
	</body>
</html>
